import { Component } from "react";
import Comment from "./components/comment.jsx";
import ZuJian from "./components/zujian2";
import ReactDom from "react-dom";


class App extends Component {
  state={
    newsList:[
      {
        id:'001',
        content:'坚定不移走中国特色社会主义法治道路',
        copyRight:'新华社',
        likeCount:774
      },
      {
        id:'002',
        content:'年度法治人物——倪伯苍',
        copyRight:'央视网',
        likeCount:454
      },
      {
        id:'003',
        content:'岁末年终 愿这份“温良”伴你乘风破浪',
        copyRight:'央视新闻客户端',
        likeCount:1233
      }
    ],
    title:'默认标题'
  }

  addCount = (id,title)=>{
    console.log(title);
    this.setState({
      newsList:this.state.newsList.map(item =>{
        if(item.id === id){
           item.likeCount =item.likeCount + 1
           return item
        }else{
          return item
        }
      }),
      title: title
    })
  }
  
  render() {
    return (
      <>
        <Comment newsList = {this.state.newsList} addCount={this.addCount} />
        <ZuJian title={this.state.title} />
      </>
    );
  }
}
ReactDom.render(<App />,document.getElementById('root'))